package com.fuyao.cloud.daemon.quartz.task;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;
import com.fuyao.cloud.admin.api.feign.RemoteUserInfoService;
import com.fuyao.cloud.common.core.constant.SecurityConstants;
import com.fuyao.cloud.daemon.quartz.constants.CloudQuartzEnum;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 消息发送定时任务
 *
 * @author lyhil
 * @date 2022年5月5日
 */
@Slf4j
@Component("syncDataTask")
@AllArgsConstructor
public class SpringBeanSyncDataTask {

    private final RemoteUserInfoService userInfoService;

    /**
     * 执行方法 同步OA数据
     * @param param 参数 type|jobName 类型|定时任务名称
     */
    @SneakyThrows
    public String runSyncOAData(String param) {

        log.info(" SpringBeanMessageTask param:{}:", param);
        log.info(" run date time :{}", LocalDateTimeUtil.now());

        this.userInfoService.syncData(SecurityConstants.FROM_IN);

        if (StrUtil.isEmpty(param)) {
            log.error("执行参数为空：{}", param);
            return CloudQuartzEnum.JOB_LOG_STATUS_FAIL.getType();
        }

        return CloudQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
    }
}
